home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10399 < prev    next >
Encoding:
Text File  |  1996-08-05  |  9.2 KB  |  465 lines

  1. Newsgroups: comp.lang.c++
  2. Path: leeds.ac.uk!news
  3. From: men3sd@leeds.ac.uk (Stephen Davison)
  4. Subject: Desperate, and Dumb!!!
  5. Message-ID: <313E0301.15FB7483@leeds.ac.uk>
  6. NNTP-Posting-Host: englib4.leeds.ac.uk
  7. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3C sun4m)
  8. Content-Type: text/plain; charset=us-ascii
  9. Organization: University of Leeds
  10. MIME-Version: 1.0
  11. Date: Wed, 6 Mar 1996 21:26:26 +0000 (GMT)
  12. CC: stephen@emissive.demon.co.uk
  13. Content-Transfer-Encoding: 7bit
  14.  
  15. Hi,
  16.  
  17. Only been C++'ing for about 2 months now and need a little help to get my project going so that I can finish
  18. it.  I have copied a menu programme form a book, and have been trying to extend it so that is can call funcions
  19. that a) have parameters, b) return other than void.
  20.  
  21. I have put some of the code bellow the error messages.  It would be tops if some out there who knows what going
  22. on, could point me in the right direction.  I really don't know what else to do!
  23.  
  24. ********* Error's
  25. englib4% (337) !!
  26. make laycon
  27. Building start Executable
  28. Compiling and Linking Application
  29. CC -I/home/sunserv5_c/men3sd/step/classes -I/home/sunserv5_c/men3sd/step/men3sd -I/apps/steptools/include \
  30. -o laycon laycon.c \
  31. -L/home/sunserv5_c/men3sd/step/classes -L/home/sunserv5_c/men3sd/step/men3sd -L/apps/steptools/lib -lClasses
  32. -lrose  \
  33.         -lm
  34. "laycon.c", line 46: Error: Could not find a match for ActionItem<RoseDesign*>::ActionItem(char*, RoseDesign*).
  35. "laycon.c", line 47: Error: Could not find a match for ActionItem<void*>::ActionItem(char*, void()).
  36. 2 Error(s) detected.
  37. *** Error code 2
  38. make: Fatal error: Command failed for target `laycon'
  39. englib4% (338) 
  40.  
  41.  
  42. laycon.c
  43. //    laycon.c
  44.  
  45. #include <rose.h>
  46. #include <sls_layered_manufacturing.h>
  47. #include "menu.h"
  48. #include "getFileName.h"
  49.  
  50. void TestLine()
  51. {
  52. }
  53.  
  54. void TestPoly()
  55. {
  56. }
  57.  
  58. RoseDesign* OpenRoseFile(RoseDesign* designDataPtr)
  59. {
  60.     FileName fileName;
  61.     if (fileName.valid())
  62.     {
  63.         //designDataPtr = ROSE.useDesign(*fileName.fileName());
  64.     }
  65.     return(designDataPtr);
  66. }
  67.  
  68. void OpenFile()
  69. {
  70.     cout << "OPEN FILE NAME" << endl;
  71.     fn.display();
  72.     if (fn.valid())
  73.     {
  74.         cout << "Valid File Name" << fn.fileName();
  75.     }
  76. }
  77.  
  78. int main()
  79. {
  80.     RoseDesign* designDataPtr;
  81.     menu myMenu ( "MAIN MENU - LAYCON (c) 1996",
  82.     new ActionItem<void*>("EXIT LAYCON" ),
  83.     new ActionItem<RoseDesign*>("Open a design file", OpenRoseFile(designDataPtr)),
  84.     new ActionItem<void*>("New", OpenFile),
  85.     new SubMenuItem ("Manuipulate" ,
  86.         new menu ("MANIPULATE MENU - LAYCON (c) 1996",
  87.             new ActionItem<void*> ("back to MAIN MENU"),
  88. //            new ActionItem ("Move", TestLine),
  89. //            new ActionItem ("Rotate", TestPoly), 
  90. //            new ActionItem ("Scale", TestLine),
  91.         MenuItem::END_ITEM ) ),
  92. //    new SubMenuItem ("Sinterstation" ,
  93. //        new menu ("SINTERSTATION MENU - LAYCON (c) 1996",
  94. //            new ActionItem ("back to MAIN MENU"),
  95. //            new ActionItem ("Generate Scan Vectors", TestLine),
  96. //            new ActionItem ("Generate Sinterstation Data Files"),
  97. //        MenuItem::END_ITEM ) ),
  98. //    new ActionItem("Help", TestLine),
  99. //    new ActionItem("Save the design file", TestLine),
  100.     MenuItem::END_ITEM ) ;
  101.  
  102.     myMenu.activate() ;
  103. }
  104.  
  105.  
  106.  
  107. *******   menu.h
  108.  
  109.  
  110. #ifndef menu_h
  111. #define menu_h
  112.  
  113.  
  114.  
  115. //
  116. //    Experimental menu system.
  117. //
  118.  
  119. #include <iostream.h>
  120. #include <stdarg.h>
  121. #include <stdio.h>
  122. #include <string.h>
  123. #include <rose.h>
  124.  
  125. typedef char * PtrChar ;
  126.  
  127. class MenuItem
  128. {
  129. protected:
  130.     PtrChar label ;
  131.     MenuItem * next ;
  132. public:
  133.     MenuItem(const PtrChar l = "", MenuItem *const n = 0)
  134.         :    label(strcpy(new char [strlen(l)+1], l)), next(n)
  135.         { }
  136.     virtual ~MenuItem()
  137.     {
  138.         delete label ; label = 0 ;
  139.         delete next ; next = 0 ; }
  140.     void connect(MenuItem *const item)
  141.     {
  142.         next = item ;
  143.     }
  144.  
  145.     virtual MenuItem * deepCopy() const = 0 ;
  146.     virtual BOOL activate(const int, const int) const = 0 ;
  147.     virtual void print(const int count) const
  148.     {
  149.         cout << "\t" << count << ": " << label << endl ;
  150.         if (next != 0)
  151.         {
  152.             next->print(count+1) ;
  153.             }
  154.     }
  155.     enum { END_ITEM = 0 } ;
  156. } ;
  157.  
  158. typedef MenuItem * PtrMenuItem ;
  159.  
  160. class menu 
  161. {
  162. protected:
  163.     PtrChar label ;
  164.     PtrMenuItem root ;
  165. public:
  166.     menu(const PtrChar l, const PtrMenuItem r = 0)
  167.     :    label(strcpy(new char [strlen(l)+1], l) ), root(r)
  168.     { }
  169.  
  170. //
  171.     menu(const PtrChar ...) ;
  172.     menu(const menu & source)
  173.     :    root(0), label(0)
  174.     {
  175.         *this = source ;
  176.     }
  177.     ~menu()
  178.     {
  179.         delete label ; label = 0 ;
  180.         delete root ; root = 0 ;
  181.     }
  182.     menu & operator = (const menu & source)
  183.     {
  184.         this->menu::~menu() ;
  185.         if (source.label != 0)
  186.         {
  187.             label = strcpy(new char [strlen(source.label)+1], source.label) ;
  188.         }
  189.         if (source.root != 0)
  190.         {
  191.             root = source.root->deepCopy() ;
  192.         }
  193.         return *this ;
  194.     }
  195.     menu * deepCopy() const
  196.     {
  197.         return new menu (label, (root == 0) ? 0 : root->deepCopy() ) ;
  198.     }
  199.     void activate() const ;
  200. } ;
  201.  
  202.  
  203. typedef menu * PtrMenu ;
  204.  
  205. //
  206. menu::menu(const PtrChar menuLabel ...)
  207.     :    label(strcpy(new char [strlen(menuLabel) + 1], menuLabel))
  208. {    
  209.     va_list parameterList ;
  210.     va_start(parameterList, menuLabel) ;
  211.     root = va_arg(parameterList, PtrMenuItem) ;
  212.     PtrMenuItem endOfList = root ;
  213.     while (1)
  214.     {
  215.         const PtrMenuItem nextitem = va_arg(parameterList, PtrMenuItem) ;
  216.     if (nextitem == 0) break ;
  217.         endOfList->connect(nextitem) ;
  218.         endOfList = nextitem ;
  219.     }
  220.     va_end(parameterList) ;
  221. }
  222.  
  223. //
  224. void menu::activate() const
  225. {
  226.     int choice ;
  227.     do
  228.     {
  229.         cout << endl << label << endl ;
  230.         root->print(1) ;
  231.         cout << endl << "Your selection: " ;
  232.         cin >> choice ;
  233.     }
  234.     while (root->activate(choice, 1) ) ;
  235. }
  236.  
  237. //
  238. static inline void unknownOption(int number)
  239. {
  240.     cerr << endl << "Item " << number << " not a valid option." << endl ;
  241. }
  242.  
  243. //
  244. class SubMenuItem : public MenuItem
  245. {
  246. protected:
  247.     PtrMenu subMenu ;
  248. public:
  249.     SubMenuItem(const PtrChar l, const PtrMenu m, SubMenuItem *const n = 0)
  250.         :    MenuItem(l, n), subMenu(m)
  251.     { }
  252.     ~SubMenuItem()
  253.     {
  254.         delete subMenu ; 
  255.     }
  256.     PtrMenuItem deepCopy() const
  257.     {
  258.         return new SubMenuItem (label, subMenu->deepCopy(),
  259.             (SubMenuItem *const)((next == 0) ? 0 : next->deepCopy())) ;
  260.     }
  261.     BOOL activate(const int, const int) const ;
  262.     void print(const int count) const
  263.     {
  264.         cout << "\t" << count << ": " << label << "  ==>" << endl ;
  265.         if (next != 0)
  266.         {
  267.             next->print(count+1) ;
  268.         }
  269.     }
  270. } ;
  271.  
  272. //
  273. BOOL SubMenuItem::activate(const int target, const int count) const
  274. {
  275.     if (target == count)
  276.     {
  277.         if (subMenu != 0)
  278.         {
  279.             subMenu->activate() ;
  280.         }
  281.         else
  282.         {
  283.             cerr << "Empty menu activates." << endl ;
  284.         }
  285.     }
  286.     else if ((target > count) && (next != 0))
  287.     {
  288.         return next->activate(target, count+1) ;
  289.     }
  290.     else
  291.     {
  292.         unknownOption(target) ;
  293.     }
  294.     return TRUE ;
  295. }
  296.  
  297.  
  298. //typedef void (*PtrVoidFunction)() ;
  299. //
  300. template <class any>
  301. class ActionItem : public MenuItem
  302. {
  303. protected:
  304.         {
  305.         return new menu (label, (root == 0) ? 0 : root->deepCopy() ) ;
  306.     }
  307.     void activate() const ;
  308. } ;
  309.  
  310.  
  311. typedef menu * PtrMenu ;
  312.  
  313. //
  314. menu::menu(const PtrChar menuLabel ...)
  315.     :    label(strcpy(new char [strlen(menuLabel) + 1], menuLabel))
  316. {    
  317.     va_list parameterList ;
  318.     va_start(parameterList, menuLabel) ;
  319.     root = va_arg(parameterList, PtrMenuItem) ;
  320.     PtrMenuItem endOfList = root ;
  321.     while (1)
  322.     {
  323.         const PtrMenuItem nextitem = va_arg(parameterList, PtrMenuItem) ;
  324.     if (nextitem == 0) break ;
  325.         endOfList->connect(nextitem) ;
  326.         endOfList = nextitem ;
  327.     }
  328.     va_end(parameterList) ;
  329. }
  330.  
  331. //
  332. void menu::activate() const
  333. {
  334.     int choice ;
  335.     do
  336.     {
  337.         cout << endl << label << endl ;
  338.         root->print(1) ;
  339.         cout << endl << "Your selection: " ;
  340.         cin >> choice ;
  341.     }
  342.     while (root->activate(choice, 1) ) ;
  343. }
  344.  
  345. //
  346. static inline void unknownOption(int number)
  347. {static inline void unknownOption(int number)
  348. {
  349.     cerr << endl << "Item " << number << " not a valid option." << endl ;
  350. }
  351.  
  352. //
  353. class SubMenuItem : public MenuItem
  354. {
  355. protected:
  356.     PtrMenu subMenu ;
  357. public:
  358.     SubMenuItem(const PtrChar l, const PtrMenu m, SubMenuItem *const n = 0)
  359.         :    MenuItem(l, n), subMenu(m)
  360.     { }
  361.     ~SubMenuItem()
  362.     {
  363.         delete subMenu ; 
  364.     }
  365.     PtrMenuItem deepCopy() const
  366.     {
  367.         return new SubMenuItem (label, subMenu->deepCopy(),
  368.             (SubMenuItem *const)((next == 0) ? 0 : next->deepCopy())) ;
  369.     }
  370.     BOOL activate(const int, const int) const ;
  371.     void print(const int count) const
  372.     {
  373.         cout << "\t" << count << ": " << label << "  ==>" << endl ;
  374.         if (next != 0)
  375.         {
  376.             next->print(count+1) ;
  377.         }
  378.     }
  379. } ;
  380.  
  381. //
  382. BOOL SubMenuItem::activate(const int target, const int count) const
  383. {
  384.     if (target == count)
  385.     {
  386.         if (subMenu != 0)
  387.         {
  388.             subMenu->activate() ;
  389.         }
  390.         else
  391.             else
  392.         {
  393.             cerr << "Empty menu activates." << endl ;
  394.         }
  395.     }
  396.     else if ((target > count) && (next != 0))
  397.     {
  398.         return next->activate(target, count+1) ;
  399.     }
  400.     else
  401.     {
  402.         unknownOption(target) ;
  403.     }
  404.     return TRUE ;
  405. }
  406.  
  407.  
  408. //typedef void (*PtrVoidFunction)() ;
  409. //
  410. template <class any>
  411. class ActionItem : public MenuItem
  412. {
  413. protected:
  414.     typedef void (*PtrVoidFunction)(any);
  415. //    any *() action;
  416.  
  417.     PtrVoidFunction action ;
  418.  
  419. public:
  420.     ActionItem<any>(const PtrChar l, /*PtrVoidFunction */ any * f,
  421.                 const PtrMenuItem n = 0)
  422.         : MenuItem(l, n), action(*f)
  423.     { }
  424.     ActionItem<any>(const PtrChar l)
  425.         : MenuItem(l), action(0)
  426.     { }
  427.     PtrMenuItem deepCopy() const
  428.     {
  429.         return new ActionItem<any>(label, action,
  430.                 (next == 0) ? 0 : next->deepCopy() ) ;
  431.     }
  432.     BOOL activate(const int, const int) const ;
  433.     BOOL RETURN()
  434.     {    return FALSE ;
  435.     }
  436.         
  437. } ;
  438. template<class any>
  439.  
  440. //
  441. BOOL ActionItem<any>::activate(const int target, const int count) const
  442. {
  443.     const int RETURN = 0 ;
  444.     if (target == count)
  445.     {
  446.         if (action == RETURN)
  447.         {
  448.             return FALSE ;
  449.         }
  450.         (*action)/*()*/ ;
  451.     }
  452.     else if ((target > count) && (next != 0))
  453.     {
  454.         return next->activate(target, count+1) ;
  455.     }
  456.     else
  457.     {
  458.         unknownOption(target) ;
  459.     }
  460.     return TRUE ;
  461. }
  462.  
  463.  
  464. #endif
  465.